//
// Copyright © 2021 dev. All rights reserved.
// 

#import "NSURL+RealHome.h"
@import Darwin.POSIX.pwd;

@implementation NSURL (RealHome)
+(NSURL *)realHomeDirectoryURL{
    static dispatch_once_t onceToken;
    static NSURL * _home;
    dispatch_once(&onceToken, ^{
         struct passwd * pwuid = getpwuid(getuid());
        if (!pwuid) {
            _home = [NSURL fileURLWithPath:NSHomeDirectory()];
        }
        _home = [NSURL fileURLWithFileSystemRepresentation:pwuid->pw_dir isDirectory:YES relativeToURL:nil];
    });
    return _home;
}
@end
